home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / GNU / GNUPLOTsrc.lha / term / hppj.trm < prev    next >
Encoding:
Text File  |  1996-01-22  |  7.1 KB  |  256 lines

  1. /*
  2.  * $Id: hppj.trm,v 1.6 1995/12/20 21:47:55 drd Exp $
  3.  *
  4.  */
  5.  
  6. /* GNUPLOT - hppj.trm */
  7. /*
  8.  * Copyright (C) 1990   
  9.  *
  10.  * Permission to use, copy, and distribute this software and its
  11.  * documentation for any purpose with or without fee is hereby granted, 
  12.  * provided that the above copyright notice appear in all copies and 
  13.  * that both that copyright notice and this permission notice appear 
  14.  * in supporting documentation.
  15.  *
  16.  * Permission to modify the software is granted, but not the right to
  17.  * distribute the modified code.  Modifications are to be distributed 
  18.  * as patches to released version.
  19.  *  
  20.  * This software  is provided "as is" without express or implied warranty.
  21.  * 
  22.  * This file is included by ../term.c.
  23.  *
  24.  * This terminal driver supports:
  25.  *  hppj
  26.  *
  27.  * AUTHORS
  28.  *  Dan Merget (danm@sr.hp.com)
  29.  *
  30.  * This file was based on the hpljii file by:
  31.  *  John Engels
  32.  *  Russell Lang
  33.  *  Maurice Castro
  34.  *
  35.  * send your comments or suggestions to (info-gnuplot@dartmouth.edu).
  36.  * 
  37.  */
  38.  
  39. /* The following HP laserjet series II driver uses generic bit mapped graphics
  40.  * routines from bitmap.c to build up a bit map in memory.
  41.  */
  42.  
  43. /*
  44.  * adapted to the new terminal layout by Stefan Bodewig (Dec. 1995)
  45.  */
  46.  
  47. #ifndef GOT_DRIVER_H
  48. #include "driver.h"
  49. #endif
  50.  
  51. #ifdef TERM_REGISTER
  52. register_term(hppj)
  53. #endif
  54.  
  55. #ifdef TERM_PROTO
  56. TERM_PUBLIC void HPPJoptions __P((void));
  57. TERM_PUBLIC void HPPJinit __P((void));
  58. TERM_PUBLIC void HPPJreset __P((void));
  59. TERM_PUBLIC void HPPJgraphics __P((void));
  60. TERM_PUBLIC void HPPJtext __P((void));
  61. TERM_PUBLIC void HPPJlinetype __P((int linetype));
  62. #define HPPJmove       b_move
  63. #define HPPJvector     b_vector
  64. #define HPPJtext_angle b_text_angle
  65. #define HPPJput_text   b_put_text
  66.  
  67. /* We define 3 different font sizes: 5x9, 9x17, and 13x25 */
  68.  
  69. #define HPPJ_DPI 180   /* dots per inch */
  70. #define HPPJ_PLANES 3  /* color planes */
  71. #define HPPJ_COLORS (1 << HPPJ_PLANES)
  72. /* make XMAX and YMAX a multiple of 8 */
  73. #define HPPJ_XMAX (8*(unsigned int)(9.5 * HPPJ_DPI / 8.0 + 0.9))
  74. #define HPPJ_YMAX (8 * HPPJ_DPI)
  75.  
  76. /* default values for term_tbl */
  77. #define HPPJ_9x17_VCHAR FNT9X17_VCHAR
  78. #define HPPJ_9x17_HCHAR FNT9X17_HCHAR
  79. #define HPPJ_9x17_VTIC (FNT9X17_VCHAR / 2)
  80. #define HPPJ_9x17_HTIC (FNT9X17_HCHAR / 2)
  81. #endif /* TERM_PROTO */
  82.  
  83. #ifndef TERM_PROTO_ONLY
  84. #ifdef TERM_BODY
  85. static int hppj_font = FNT9X17;
  86.  
  87. TERM_PUBLIC void HPPJoptions()
  88. {
  89.     char opt[10];
  90. #define HPPJERROR "expecting font size FNT5X9, FNT9X17, or FNT13X25"
  91.  
  92.     term_options[0]='\0'; /* default to empty string and 9x17 font */
  93.     hppj_font = FNT9X17;  /* in case of error or empty options     */
  94.  
  95.     if ( !END_OF_COMMAND ) {
  96.         if ( token[c_token].length > 8 ) {
  97.             int_error(HPPJERROR, c_token);
  98.        }
  99.  
  100.         capture(opt, c_token, c_token, 4);
  101.         if ( !strcmp(opt, "FNT5X9") ) {
  102.             hppj_font = FNT5X9;
  103.             strcpy(term_options, "FNT5X9");
  104.     } else if ( !strcmp(opt, "FNT9X17") ) {
  105.            hppj_font = FNT9X17;
  106.             strcpy(term_options, "FNT9X17");
  107.     } else if ( !strcmp(opt, "FNT13X25") ) {
  108.            hppj_font = FNT13X25;
  109.             strcpy(term_options, "FNT13X25");
  110.     } else {
  111.         int_error(HPPJERROR, c_token);
  112.     }
  113.     c_token++;
  114.     }
  115. }
  116.  
  117.  
  118. TERM_PUBLIC void HPPJinit()
  119. {
  120. #ifdef REOPEN_BINARY
  121.     reopen_binary();
  122. #endif
  123. }
  124.  
  125.  
  126. TERM_PUBLIC void HPPJreset()
  127. {
  128. #ifdef vms
  129.     fflush_binary();
  130. #endif /* vms */
  131. }
  132.  
  133.  
  134. TERM_PUBLIC void HPPJgraphics()
  135. {
  136.     switch ( hppj_font ) {
  137.       case FNT5X9 :
  138.     term->v_char = FNT5X9_VCHAR;
  139.     term->h_char = FNT5X9_HCHAR;
  140.     term->v_tic = FNT5X9_VCHAR / 2;
  141.     term->h_tic = FNT5X9_HCHAR / 2;
  142.     break;
  143.       case FNT9X17 :
  144.     term->v_char = FNT9X17_VCHAR;
  145.     term->h_char = FNT9X17_HCHAR;
  146.     term->v_tic = FNT9X17_VCHAR / 2;
  147.     term->h_tic = FNT9X17_HCHAR / 2;
  148.     break;
  149.       case FNT13X25 :
  150.     term->v_char = FNT13X25_VCHAR;
  151.     term->h_char = FNT13X25_HCHAR;
  152.     term->v_tic = FNT13X25_VCHAR / 2;
  153.     term->h_tic = FNT13X25_HCHAR / 2;
  154.     break;
  155.     }
  156.     b_charsize(hppj_font);
  157.  
  158.     b_makebitmap(HPPJ_XMAX, HPPJ_YMAX, HPPJ_PLANES);
  159. }
  160.  
  161.  
  162. TERM_PUBLIC void HPPJtext()
  163. {
  164.     int x, plane, y;    /* loop indexes */
  165.     int minRow, maxRow;    /* loop bounds */
  166.     int numBytes;    /* Number of run-length coded bytes to output */
  167.     int numReps;    /* Number of times the current byte is repeated */
  168.  
  169.     fprintf(outfile, "\033E\033*t%dR\033*r%dS", HPPJ_DPI, HPPJ_YMAX);
  170.     fprintf(outfile, "\033*b0X\033*b0Y\033*r%dU", HPPJ_PLANES);
  171.     fprintf(outfile, "\033*v%dA\033*v%dB\033*v%dC\033*v%dI", 90, 88, 85, 0);
  172.     fprintf(outfile, "\033*v%dA\033*v%dB\033*v%dC\033*v%dI", 53,  8, 14, 1);
  173.     fprintf(outfile, "\033*v%dA\033*v%dB\033*v%dC\033*v%dI",  3, 26, 22, 2);
  174.     fprintf(outfile, "\033*v%dA\033*v%dB\033*v%dC\033*v%dI",  4,  4, 29, 3);
  175.     fprintf(outfile, "\033*v%dA\033*v%dB\033*v%dC\033*v%dI", 53,  5, 25, 4);
  176.     fprintf(outfile, "\033*v%dA\033*v%dB\033*v%dC\033*v%dI",  2, 22, 64, 5);
  177.     fprintf(outfile, "\033*v%dA\033*v%dB\033*v%dC\033*v%dI", 89, 83, 13, 6);
  178.     fprintf(outfile, "\033*v%dA\033*v%dB\033*v%dC\033*v%dI",  4,  4,  6, 7);
  179.     fprintf(outfile, "\033*b1M\033*r1A");
  180.  
  181.     /* dump bitmap in raster mode using run-length encoding */
  182.     for ( x = HPPJ_XMAX - 1 ; x >= 0 ; --x ) {
  183.         for ( plane = 0 ; plane < HPPJ_PLANES ; plane++ ) {
  184.             minRow = b_psize * plane;
  185.             maxRow = b_psize * plane + b_psize - 1;
  186.  
  187.             /* Print column header */
  188.             numBytes = 0;
  189.             for ( y = maxRow ; y >= minRow ; --y ) {
  190.                 if ( y == minRow || *((*b_p)[y]+x) != *((*b_p)[y-1]+x) ) {
  191.                     numBytes += 2;
  192.                 }
  193.             }
  194.             fprintf(outfile, "\033*b%d", numBytes);
  195.             (void) fputc((char)(plane < HPPJ_PLANES - 1 ? 'V' : 'W'), outfile);
  196.  
  197.             /* Print remainder of column */
  198.             numReps = 0;
  199.             for ( y = maxRow ; y >= minRow ; --y ) {
  200.                 if ( y == minRow || *((*b_p)[y]+x) != *((*b_p)[y-1]+x) ) {
  201.                     (void) fputc( (char)(numReps), outfile );
  202.                     (void) fputc( (char)(*((*b_p)[y]+x)), outfile );
  203.                     numReps = 0;
  204.                 } else {
  205.                     numReps++;
  206.                 }
  207.             }
  208.         }
  209.     }
  210.     fprintf(outfile, "\033*r1B\033E");
  211.  
  212.     b_freebitmap();
  213. }
  214.  
  215.  
  216. TERM_PUBLIC void HPPJlinetype(linetype)
  217.     int linetype;
  218. {
  219.     if ( linetype >= 0 ) {
  220.         b_setlinetype(0);
  221.         b_setvalue((linetype % (HPPJ_COLORS-1)) + 1);
  222.     } else {
  223.         b_setlinetype(linetype + 2);
  224.         b_setvalue(HPPJ_COLORS - 1);
  225.     }
  226. }
  227.  
  228. #endif /* TERM_BODY */
  229.  
  230. #ifdef TERM_TABLE
  231.  
  232. TERM_TABLE_START(hppj_driver)
  233.     "hppj", "HP PaintJet and HP3630 [FNT5X9 FNT9X17 FNT13X25]",
  234.        HPPJ_XMAX, HPPJ_YMAX,
  235.        HPPJ_9x17_VCHAR, HPPJ_9x17_HCHAR, HPPJ_9x17_VTIC, HPPJ_9x17_HTIC,
  236.        HPPJoptions, HPPJinit, HPPJreset, HPPJtext, null_scale, HPPJgraphics,
  237.        HPPJmove, HPPJvector, HPPJlinetype, HPPJput_text, HPPJtext_angle,
  238.        null_justify_text, do_point, do_arrow, set_font_null
  239. TERM_TABLE_END(hppj_driver)
  240.  
  241. #undef LAST_TERM
  242. #define LAST_TERM hppj_driver
  243.  
  244. #endif /* TERM_TABLE */
  245. #endif /* TERM_PROTO_ONLY */
  246.  
  247. /*
  248.  * NAME: hppj
  249.  *
  250.  * OPTIONS: font (legal FNT5X9, FNT9X17, FNT13X25; default FNT9X17)
  251.  *
  252.  * SUPPORTS: HP PaintJet and HP3630
  253.  *
  254.  * Further Info: none
  255.  *
  256.  */